<!--
 * @Author: windys
 * @Description: 相关
 * @Date: 2022-03-08 10:26:27
-->
<template>
  <div class="relevant_page">
    <div class="list">
      <van-list
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div
          class="list_item"
          v-for="(item, index) in list"
          :key="index"
          @click="handleChangeCrouse(item)"
        >
          <div class="left">
            <van-image
              width="120"
              height="100"
              radius="5"
              :src="item.courseUrl"
            />
          </div>
          <div class="right">
            <div class="name">{{ item.courseName }}</div>
            <div class="sp_info">
              <van-image width="20" height="20" :src="item.courseUrl" round />
              <span>{{ item.spcolumnName }}</span>
            </div>
            <div class="desc">
              <van-rate v-model="item.level" readonly size="14px" color="red" />
              <span
                >{{ item.videoCount }}节 · {{ item.viewNum }}观看 ·
                {{ item.commentNum }}评论</span
              >
            </div>
            <div class="footer">
              <span class="price">{{
                item.price > 0 ? item.price + "金石" : "免费"
              }}</span>
              <span class="vip">
                <i class="iconfont icon-VIP1"></i>
                {{
                  item.vipPrice > 0 ? item.vipPrice + "金石" : "VIP免费"
                }}</span
              >
            </div>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>



<script >
import { defineComponent, reactive, ref } from "vue";
import { querySqList } from "@/api/crouse";
import { useRoute } from "vue-router";
export default defineComponent({
  props: {
    spcolumnId: {
      type: String,
      default: () => "",
    },
  },
  setup(props, { emit }) {
    const list = ref([]);
    const loading = ref(false);
    const finished = ref(false);
    const route = useRoute();
    const query = reactive({
      pageIndex: 0,
      pageSize: 10,
      spcolumnId: props.spcolumnId,
      excludeCourseIds: route.query.courseId,
    });

    // 加载
    const onLoad = async () => {
      query.pageIndex++;
      const res = await querySqList(query);
      if (res) {
        list.value = list.value.concat(res);
        loading.value = false;
        if (res.length <= 0) {
          finished.value = true;
        } else {
          finished.value = false;
        }
      }
    };

    const handleChangeCrouse = (item) => {
      emit("handleChangeCrouse", item);
    };

    return {
      loading,
      finished,
      list,
      query,
      onLoad,
      handleChangeCrouse,
    };
  },
});
</script>



<style lang="scss" scoped>
.relevant_page {
  .list {
    padding: 20px 10px;
    .list_item {
      height: 100px;
      display: flex;
      flex-direction: row;
      margin-bottom: 10px;
      padding-bottom: 10px;
      border-bottom: 1px solid #f1ecec;
      .left {
        width: 120px;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .right {
        width: calc(100% - 120px);
        font-size: 12px;
        display: flex;
        flex-direction: column;
        padding: 5px;
        .name {
          font-size: 14px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .sp_info {
          height: 20px;
          line-height: 20px;
          display: flex;
          align-items: center;
          margin: 5px 0;
          span {
            margin-left: 5px;
            color: #afadad;
          }
        }
        .desc {
          height: 15px;
          line-height: 15px;
          display: flex;
          align-items: center;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          span {
            margin-left: 10px;
            color: #777676;
            position: relative;
            top: 1px;
          }
        }
        .footer {
          font-size: 12px;
          margin-top: 10px;
          display: flex;
          align-items: center;
          .price {
            color: #c96819;
          }
          .vip {
            display: flex;
            color: red;
            align-items: center;
            margin-left: 10px;
            i {
              margin-right: 5px;
              font-size: 16px;
            }
          }
        }
      }
    }
  }
}
</style>
